import numpy as np
import matplotlib.pyplot as plt

# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

def f(x):
    return (2*x + 3) / (x - 1)

# 生成数据点
x_left = np.linspace(-10, 0.9, 400)
x_right = np.linspace(1.1, 10, 400)

plt.figure(figsize=(10, 6))
plt.plot(x_left, f(x_left), 'blue', label='f(x) = (2x + 3)/(x - 1)', linewidth=2)
plt.plot(x_right, f(x_right), 'blue', linewidth=2)

# 绘制渐近线
plt.axhline(2, color='red', linestyle='--', alpha=0.7, label='水平渐近线 y=2')
plt.axvline(1, color='green', linestyle='--', alpha=0.7, label='铅直渐近线 x=1')

plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.title('水平渐近线与铅直渐近线示例', fontsize=14)
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()